package JVM相关知识;

import java.io.*;

/**
 * @author coderFu
 * @create 2022/1/4
 * 监控线程的运行情况  jconsole jstack
 */
public class JstackMonitorThreadTest {

    public static void main(String[] args) throws IOException {
        //需要输入一个字符
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        bufferedReader.readLine();
        // 启动永久运行的线程
        new JstackMonitorThreadTest().CreateBusThread();
        bufferedReader.readLine();
        //启动永久等待的线程池
        new JstackMonitorThreadTest().blockWait(new Object());
        // main 线程结束
    }

    /**
     * 永久运行的线程
     */
    public void CreateBusThread(){
        Thread thread = new Thread(()->{
            while (true){
//                System.out.println("我一直在运行");
            }
        },"goodName");
        thread.start();
        System.out.println("test BusyThread running");
    }

    /**
     * 锁等待的线程
     */
    public void blockWait(Object lock){
        Thread thread =  new Thread(()->{
            synchronized (lock){
                System.out.println("锁等待");
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("TestBlockWaiting");
        },"waitThread");
        thread.start();
    }

}
